<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        // js中定义了一个对象 prototype  给函数使用   原型对象

        //   给实例提供公共的属性和方法

        // 构造函数  建议首字母大写
        function Dog(name , age) {
            this.name = name ;
            this.age = age ;
        }
        // say方法是公共的
        Dog.prototype.say = function() {
            console.log(this.name + this.age);
        }
        Dog.prototype.type = '狗子' ;


        const d1 = new Dog('柯基' , 3) ;

        const d2 = new Dog('td' , 2) ;

        console.log(d1);

        console.log(d1.type);


        // const arr = [1,2,3];
        // console.log(arr);

        console.log(d2.type);

        d2.say()


        console.log(d1.say === d2.say);   // true

    </script>
    
</body>
</html>